package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Realtest;
import com.ruoyi.system.service.IRealtestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * realtestController
 *
 * @author ruoyi
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/system/realtest")
public class RealtestController extends BaseController
{
    @Autowired
    private IRealtestService realtestService;

    /**
     * 查询realtest列表
     */
    @PreAuthorize("@ss.hasPermi('system:realtest:list')")
    @GetMapping("/list")
    public TableDataInfo list(Realtest realtest)
    {
        startPage();
        List<Realtest> list = realtestService.selectRealtestList(realtest);
        return getDataTable(list);
    }


    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Realtest> util = new ExcelUtil<Realtest>(Realtest.class);
        util.importTemplateExcel(response, "用户数据");
    }

    /**
     * 导出realtest列表
     */
    @PreAuthorize("@ss.hasPermi('system:realtest:export')")
    @Log(title = "realtest", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Realtest realtest)
    {
        List<Realtest> list = realtestService.selectRealtestList(realtest);
        ExcelUtil<Realtest> util = new ExcelUtil<Realtest>(Realtest.class);
        util.exportExcel(response, list, "realtest数据");
    }

    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:realtest:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Realtest> util = new ExcelUtil<Realtest>(Realtest.class);
        List<Realtest> realtestList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = realtestService.importRealtest(realtestList, updateSupport, operName);
        return success(message);
    }


    /**
     * 获取realtest详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:realtest:query')")
    @GetMapping(value = "/{ywid}")
    public AjaxResult getInfo(@PathVariable("ywid") Long ywid)
    {
        return success(realtestService.selectRealtestByYwid(ywid));
    }

    /**
     * 新增realtest
     */
    @PreAuthorize("@ss.hasPermi('system:realtest:add')")
    @Log(title = "realtest", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Realtest realtest)
    {
        return toAjax(realtestService.insertRealtest(realtest));
    }

    /**
     * 修改realtest
     */
    @PreAuthorize("@ss.hasPermi('system:realtest:edit')")
    @Log(title = "realtest", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Realtest realtest)
    {
        return toAjax(realtestService.updateRealtest(realtest));
    }

    /**
     * 删除realtest
     */
    @PreAuthorize("@ss.hasPermi('system:realtest:remove')")
    @Log(title = "realtest", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ywids}")
    public AjaxResult remove(@PathVariable Long[] ywids)
    {
        return toAjax(realtestService.deleteRealtestByYwids(ywids));
    }
}
